package TreeSet;

import demo1.Student1;

import java.util.Iterator;
import java.util.TreeSet;

public class TreeSetDemo {
    public static void main(String[] args) {
        method_2();
        //创建集合对象
        TreeSet<Student1> ts = new TreeSet<Student1>();
        //向集合中添加数据
        ts.add(new Student1("张三",19));
        ts.add(new Student1("李四",20));
        ts.add(new Student1("王五",17));
        ts.add(new Student1("黑旋风",19));
        //遍历集合
        for (Iterator it = ts.iterator(); it.hasNext();) {
            //输出集合中的数据
            System.out.println(it.next());
        }
    }

    public static void method_2() {
        TreeSet tree = new TreeSet();
        tree.add(20);
        tree.add(31);
        tree.add(10);
        tree.add(13);
        tree.add(23);
        tree.add(5);
        tree.add(51);
        tree.add(5);
        for (Iterator it = tree.iterator(); it.hasNext(); ) {
            //输出集合中的数据
            System.out.println(it.next());
        }
    }
    public void method_1() {
//       创建集合对象 自然排序 升序
        TreeSet set = new TreeSet();
        //向集合中添加数据
        set.add("abc");
        set.add("abcdef");
        set.add("acc");
        set.add("Abc");
        set.add("abcd");
        set.add("bbb");
        set.add("bbb");
        //遍历集合
        for (Iterator it = set.iterator(); it.hasNext();) {
            //输出集合中的数据
            System.out.println(it.next());
        }
    }
}
